package dolf.objects.weapons.MineDetector;

import java.awt.Color;
import java.awt.Graphics2D;
import javax.swing.ImageIcon;
import dolf.objects.CircleObject;
import dolf.objects.ImageStore;
import dolf.objects.Point;
import dolf.objects.WorldObject;
import dolf.objects.weapons.*;
import dolf.objects.weapons.Mine.*;
import dolf.window.SystemMessagesHandler;
import dolf.game.Level;
import dolf.game.Player;

public class MineDetector extends CircleObject implements Weapon, java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int Price = 70;
	public static final String Name = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.MineDetector.lang.lang").getString("name");
	public static final String WeaponType = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.MineDetector.lang.lang").getString("type");
	public static final String Description = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.MineDetector.lang.lang").getString("description");
	public static final javax.swing.ImageIcon Icon = ImageStore.getInstance().getIcon("dolf/objects/weapons/MineDetector/gfx/icon.png");
	
	private final int RANGE = 40;
	private Player pl;
	private boolean inititalized = false;
	private boolean used;
	private double state;
	
	public MineDetector(){
		super(null,5,false);
		this.setCollitabe(false);
	}
	public void paint(Graphics2D g){
		if(this.used && this.getRadius() < this.RANGE){
			if(this.getRadius() < this.RANGE){
				this.setRadius(this.getRadius()+1);
			}
			Color tmp = g.getColor();
			g.setColor(Color.GREEN);
			g.drawOval(this.getPosition().getIntX()-this.getRadius(), this.getPosition().getIntY()-this.getRadius(), 2*this.getRadius(), 2*this.getRadius());
			g.setColor(tmp);
			
		}
	}
	
	public void initialize(Player _pl){
		if(this.inititalized){
			return;
		}
		this.inititalized = true;
		this.used = false;
		this.pl = _pl;
		this.state = 1;
		this.pl.setWeaponState();
	}
	
	public void deInitialize(){
		this.pl = null;
		this.inititalized = false;
	}
	
	public void execute() {
		if(Level.getInstance().mousePressed()&&!used){
			this.used = true;
			Level.getInstance().registerObject(this);
			this.state = 0;
			this.pl.setWeaponState();
		}
		if(this.used && this.getRadius() <this.RANGE){
			for(int i = 0; i < Level.getInstance().getObjects().size(); i++){
				if(Level.getInstance().getObjects().get(i) instanceof Mine &&
						this.getPosition().getDist(Level.getInstance().getObjects().get(i).getPosition())<=this.getRadius()+6){
					((Weapon) Level.getInstance().getObjects().get(i)).remove();
					Level.getInstance().removeObject(Level.getInstance().getObjects().get(i));
					System.out.println("beep");
					
				}
			}
		}
	}

	public boolean newMotion(WorldObject object){
		return true;
	}
	
	public ImageIcon getIcon() {
		return Icon;//ImageStore.getInstance().getIcon("dolf/objects/weapons/MineDetector/gfx/icon.png");
	}

	public String getName() {
		return Name;
		/*if (messages == null) loadProperties();
		return messages.getString("name");*/
	}
	
	public String getDescription() {
		return Description;
		/*if (messages == null) loadProperties();
		return messages.getString("description");*/
	}
	public String getType(){
		return WeaponType;
	}

	public int getPrice() {
		return Price;
	}

	public void remove() {
		pl.removeWeapon(this);
		Level.getInstance().removeObject(this);
		this.pl.setAktWeapon(null);
	}
	public Player getPlayer(){
		return this.pl;
	}
	public Point getPosition(){
		return pl.getBall().getPosition();
	}
	public double getState(){
			return this.state;
	}
}
